import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
cap = cv.VideoCapture('bike.mp4')

while cap.isOpened():
    ret, frame = cap.read()

    if not ret:
        print("没有内容，退出啦 :) ")
        break
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

    cv.imshow('frame', gray)
    fCoef = np.fft.fft2(gray)
    fCoef_shifted = np.fft.fftshift(fCoef)
    msp = 20 * np.log(np.abs(fCoef))
    msp_shifted = 20 * np.log(np.abs(fCoef_shifted))
    msp = cv.cvtColor(np.uint8(msp), cv.COLOR_GRAY2BGR)
    msp_shifted = cv.cvtColor(np.uint8(msp_shifted), cv.COLOR_GRAY2BGR)
    cv.imshow('mg_spc', msp)
    cv.imshow('mg_spc_shift', msp_shifted)
    if cv.waitKey(1) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()
